package jmvm.components;

///
/// izmenjeni 16bitni GPR
///
public class GPR2 extends LogicalComponent {

	private Pin wr;
	private Pin address;
	
	public REG [] regs;
	
	
	public GPR2(int size) {
		super(1, 1, false);
		regs = new REG [size];
		for ( int i = 0 ; i<size ; i++ ) {
			regs[i].getOut(0).setIsInt();
			regs[i].getOut(0).setNumOfLines(16);
			regs[i].setInputPin(0, in[0]);
		}
		out[0].setIsInt();
		out[0].setNumOfLines(16);
		out[0]=regs[0].getOut(0);
		addSequentialComponent(this);
	}


	public void func() {
		out[0]=regs[address.getIntVal()].getOut(0);
		regs[address.getIntVal()].setPinLd(wr);
		//if ((wr != null) && (wr.getBoolVal())) 
		//	regs[address.getIntVal()] = in[0].getIntVal() & 0xffff;
		//out[0].setIntVal(regs[address.getIntVal()], false);
		
	}
	
	
	public void setPinWr(Pin wr) {
		this.wr = wr;
		wr.addChild(this);
	}
	
	public void setPinAddress(Pin address) {
		this.address = address;
		address.addChild(this);
	}
	
	public void clear() {
	//	for ( int i=0 ; i< regs.length ; i++ ) regs[i]=0;
	}

}
